namespace ActiveRecord

import System
import System.Collections
import System.Reflection


class Utils:

	public static def IsEmpty( list as IList ) as bool:
	   return list is null or list.Count == 0
	
	public static def IsEmpty( collection as ICollection ) as bool:
	   return collection is null or collection.Count == 0
	
	public static def IsEmpty( array as Array ) as bool: 
	   return array is null or array.Length == 0

	public static def IsEmpty( s as string ) as bool: 
      #debug "IsEmpty( ${s} as string )"
      return s is null or s.Length == 0

	public static def IsEmpty( s as object ) as bool: 
      #debug "IsEmpty( ${s} as object )"
      return s is null

   public static def Inspect(obj as object) as string:
      if obj is null:
         return "null"
      return obj.GetType().FullName + Environment.NewLine + \
         "   properties: " + getProperties(obj) + Environment.NewLine + \
         "   methods:    " + getMethods(obj) + Environment.NewLine + \
         "   fields:     " + getFields(obj)


   static def getProperties(obj) as string:
      ret = string.Empty
      for info as PropertyInfo in obj.GetType().GetProperties():
         try:
            ret += info.Name + ": " + info.GetValue(obj, null) + ", "
         except e:
            debug e.ToString()
      return ret

   static def getMethods(obj) as string:
      ret = string.Empty
      for info as MethodInfo in obj.GetType().GetMethods():
         try:
            ret += info.Name + ", "# + "( " + info.Parameters + ")"
         except e:
            debug e.ToString()
      return ret

   static def getFields(obj) as string:
      ret = string.Empty
      for info as FieldInfo in obj.GetType().GetFields():
         try:
            ret += info.Name + ": " + info.GetValue(obj) + ", "
         except e:
            debug e.ToString()
      return ret

